package com.woniuxy.java106crm.handler;

import com.woniuxy.java106crm.request.Message;
import com.woniuxy.java106crm.request.ResponseResult;
import com.woniuxy.java106crm.request.StateCode;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.InternalAuthenticationServiceException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理类
 */
@RestControllerAdvice
public class GlobalException {
    //登录账号密码异常
    @ExceptionHandler({BadCredentialsException.class, InternalAuthenticationServiceException.class})
    public ResponseResult<Object> handle(Exception e){
        e.printStackTrace();
        return new ResponseResult<>(StateCode.FAIL, Message.ACCOUNT_OR_PASSWORD_ERROR,null);
    }
    @ExceptionHandler(ValidatesException.class)
    public ResponseResult<Object> handler(Exception e){
        e.printStackTrace();
        return new ResponseResult<>(StateCode.FAIL,e.getMessage(),null);
    }


}
